using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
using System.Data.SqlClient;
using System.Text;

/// <summary>
/// THIS PAGE SHOWS THE DETAILS OF A DENTIST BASED ON THE 'ID' PASSED IN THE QUERYSTRING. 
/// </summary>
/// <remarks>
/// AUTHOR  : KAJAL
/// DATE    : 8 JUNE 2007
/// </remarks>
public partial class Dentist_DentistDetails : System.Web.UI.Page
{
    // creating an instance of manager class
    Manager mgr = new Manager(true,"ConnectionString");
    int DentistId = 0;
   // string Title, Keywords, Description;

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            try
            {
                if (Request.QueryString["Id"] != null)
                    IncreaseViewCounter();
                else if (RewriteModule.RewriteContext.Current.Params["Id"] != null)
                {
                    IncreaseViewCounter();
                }
                
            }
            catch(Exception ex)
            {
                Response.Write(ex.Message.ToString());
                Response.Redirect(Session["strHTTP"] + "SearchResults_dentist.aspx");
            }

            if (ViewState["pageFromOrAction"] == null)
                ViewState["pageFromOrAction"] = Session["pageFromOrAction"];
            //commented by vinayak
            //if (Request.QueryString["id"] == null || Request.QueryString["id"].ToString() == "")
            //{
            //    Response.Redirect(Session["strHttp"] + "SearchDentists_adv.aspx");
            //}
            lblMsg.Text = "";
            localFunction lfunction = new localFunction();

            peerRating.Visible = (lfunction.checkDentistLogin(false) || (lfunction.checkDentistLogin(false)));

            DntEndorsementRating1.isDentist = lfunction.checkDentistLogin(false);

            //if (lfunction.checkDentistLogin(false) || (lfunction.checkDentistLogin(false)))
            //{                
            //    peerRating.Visible = true;
            //}
            //else
            //{                
            //    peerRating.Visible = false; 
            //}

            
            try
            {
                //Added at 190908

                if (Request.QueryString["Id"] != null)
                {
                    DentistId = Convert.ToInt32(Request.QueryString["Id"].ToString());  
                }
                else if (RewriteModule.RewriteContext.Current.Params["Id"] != null)
                {
                    DentistId = Convert.ToInt32(RewriteModule.RewriteContext.Current.Params["Id"].ToString());  
                }
                Session["DentistDoctorID"] = DentistId; //Added By Wahaj Khan Nov 30 2011
                Session["isToDoctorOrDentist"] = "Dentist"; 
                              

                //End

                SqlParameter[] prm = new SqlParameter[1];
                prm[0] = new SqlParameter("@DENT_ID", SqlDbType.Int);
                prm[0].Value = DentistId;
                SqlDataReader rdr = mgr.ExecuteQuery("ADDEDIT_DENT_METACONTENT", prm);

                if (rdr.Read())
                {
                    Master.keywordsContent = rdr["META_KEYWORDS"].ToString();
                    Master.descriptionContent = rdr["META_DESCRIPTION"].ToString();
                    Master.titleContent = rdr["META_TITLE"].ToString();
                }

                rdr.Close();
            }
            catch
            {
                DentistId = 0;
            }
            //Rating1.DentistId = DentistId;
            //      
            
            DntEndorsementRating1.DentistId = DentistId;

            if (!Page.IsPostBack)
            {
                if (DentistId == 0)
                {
                    lblMsg.Text = "No Records found";
                    lblMsg.ForeColor = System.Drawing.Color.Red;
                    lblMsg.Font.Bold = true;
                }
                else
                {
                    //filling all the controls with the values from the database
                    GetSelectedDoctorName(DentistId);
                    BindBoxes(DentistId);
                    Session["DoctorDentistName"] = lblName.Text;
                    Session["DoctorDentistID"] = DentistId;
                    Session["ReceiverType"] = 4;
                }
            }
        }
       
        LinkButton2.Text = "Invite Dr. " + lblName.Text + " to be your Doc-Friend";

        if ((Request.QueryString["id"] != null) && (Session["userid"] != null))
        {
            if (Request.QueryString["id"].ToString() == Session["userid"].ToString())
            {
                peerRating.Visible = false;
            }
        }
        else if ((RewriteModule.RewriteContext.Current.Params["Id"] != null) && (Session["userid"] != null))
        {
            if (RewriteModule.RewriteContext.Current.Params["Id"].ToString() == Session["userid"].ToString())
            {
                peerRating.Visible = false;
            }
        }

    }

    #region BindBoxes
    /// <summary>
    /// to get all the details of the specified Dentist and fill the controls
    /// </summary>
    /// <param name="id"></param>
    private void BindBoxes(int id)
    {
        //to get all the details of the specified Dentist
        double overallRate = 0;
        //   try
        {
            SqlParameter[] sqlParam = new SqlParameter[1];
            sqlParam[0] = new SqlParameter("@dnt_id", SqlDbType.Int);
            sqlParam[0].Value = id;
            DataSet ds_drdet = mgr.ExecuteQuery("get_dentistdetails", sqlParam, "tbl_a");

            if (ds_drdet.Tables[0].Rows.Count > 0)
            {
                //Added by Wahaj Khan for sending Email to concerned Dentist in case of Face Page updating December 15 2011
                if (ds_drdet.Tables[0].Rows[0]["email"].ToString().Trim().Length > 0)
                    Session["DentistDoctorEmail"] = ds_drdet.Tables[0].Rows[0]["email"].ToString();
                // End Code Added by Wahaj December 15 2011


                lblName.Text = ds_drdet.Tables[0].Rows[0]["Name"].ToString();
                lblTitle.Text = ds_drdet.Tables[0].Rows[0]["Title"].ToString();
                litReviews.Text = ds_drdet.Tables[0].Rows[0]["patientreview"].ToString();
                lblmgrActivity.Text = "Not Available";
                if (ds_drdet.Tables[0].Rows[0]["MajorActivityID"].ToString() != "0")
                    lblmgrActivity.Text = ds_drdet.Tables[0].Rows[0]["MajorActivityID"].ToString();
                lblgroupprac.Text = ds_drdet.Tables[0].Rows[0]["GroupPractice"].ToString().Length > 0 ? ds_drdet.Tables[0].Rows[0]["GroupPractice"].ToString() : "Not Available";
                lbllanguage.Text = ds_drdet.Tables[0].Rows[0]["languages"].ToString().Length > 0 ? ds_drdet.Tables[0].Rows[0]["languages"].ToString() : "Not Available";
                lblAddress.Text += ds_drdet.Tables[0].Rows[0]["Address1"].ToString();
                if (ds_drdet.Tables[0].Rows[0]["Address2"].ToString().Trim().Length > 0)
                    lblAddress.Text += "<br>" + ds_drdet.Tables[0].Rows[0]["Address2"].ToString();

                if (ds_drdet.Tables[0].Rows[0]["City"].ToString().Trim().Length > 0)
                    lblAddress.Text += "<br>" + ds_drdet.Tables[0].Rows[0]["City"].ToString();
                if (ds_drdet.Tables[0].Rows[0]["State"].ToString().Trim().Length > 0)
                    lblAddress.Text += ", " + ds_drdet.Tables[0].Rows[0]["State"].ToString();
                if (ds_drdet.Tables[0].Rows[0]["ZipCode"].ToString().Trim().Length > 0)
                    lblAddress.Text += " " + ds_drdet.Tables[0].Rows[0]["ZipCode"].ToString();
                if (ds_drdet.Tables[0].Rows[0]["Phone"].ToString().Trim().Length > 0)
                    lblAddress.Text += "<br>Phone :" + ds_drdet.Tables[0].Rows[0]["Phone"].ToString();
                if (ds_drdet.Tables[0].Rows[0]["Fax"].ToString().Trim().Length > 0)
                    lblAddress.Text += "<br>Fax :" + ds_drdet.Tables[0].Rows[0]["Fax"].ToString();
                try
                {
                    lnkGoogle.NavigateUrl = "http://maps.google.com/maps?q=" + Server.UrlEncode(ds_drdet.Tables[0].Rows[0]["Address1"].ToString() + ", " + ds_drdet.Tables[0].Rows[0]["Address2"].ToString() + ", " + ds_drdet.Tables[0].Rows[0]["city"].ToString() + ", " + ds_drdet.Tables[0].Rows[0]["state"].ToString() + ", " + ds_drdet.Tables[0].Rows[0]["zipcode"].ToString()) + "&num=1&start=0";
                    lnkGoogle1.NavigateUrl = "http://maps.google.com/maps?q=" + Server.UrlEncode(ds_drdet.Tables[0].Rows[0]["Address1"].ToString() + ", " + ds_drdet.Tables[0].Rows[0]["Address2"].ToString() + ", " + ds_drdet.Tables[0].Rows[0]["city"].ToString() + ", " + ds_drdet.Tables[0].Rows[0]["state"].ToString() + ", " + ds_drdet.Tables[0].Rows[0]["zipcode"].ToString()) + "&t=h&num=1&start=0&hl=en";
                }
                catch { }
                
                //DntEndorsementRating1.rating = Convert.ToDecimal(ds_drdet.Tables[0].Rows[0]["PEERREF"].ToString());
                if ((Session["userID"] != null)&&(Session["userID"].ToString().Length>0))
                {
                    SqlParameter[] prmEndorse = new SqlParameter[3];
                    prmEndorse[0] = new SqlParameter("@id", SqlDbType.Int);
                    prmEndorse[0].Value = Session["userID"].ToString();

                    prmEndorse[1] = new SqlParameter("@isDentist", SqlDbType.Bit);
                    prmEndorse[1].Value = DntEndorsementRating1.isDentist;

                    prmEndorse[2] = new SqlParameter("@DntID", SqlDbType.Int);
                    prmEndorse[2].Value = DentistId;
                    
                    object objVal = mgr.ExecuteScalarQuery("GetDAwardedPoints_Dentist",prmEndorse);

                    DntEndorsementRating1.rating = Convert.ToDecimal(objVal);
                    DntEndorsementRating1.totalScore = 15;

                    prmEndorse = null;
                }
                else
                {
                    DntEndorsementRating1.rating = 11;
                    DntEndorsementRating1.totalScore = 15;
                }
                // lblMedicalSchool.Text = "Not Available";//Commented By Wahaj Jan 31 2012

                if (ds_drdet.Tables[0].Rows[0]["MedicalSchool"].ToString().Trim().Length != 0)
                    lblMedicalSchool.Text = ds_drdet.Tables[0].Rows[0]["MedicalSchool"].ToString();
                else
                    lblMedicalSchool.Text = "Not Available"; //Added by Wahaj Jan 31 2012

                #region -- Obsolete Code --
                /* DELETED 02/02/2007 - medical school is only one  
                 * string[] strMedschids = ds_drdet.Tables[0].Rows[0]["MedicalSchool"].ToString().Split(new char[] { ',' });
                if (ds_drdet.Tables[0].Rows[0]["MedicalSchool"].ToString() != "")
                {
                    if (strMedschids.Length != 0)
                    {
                        for (int i = 0; i < strMedschids.Length-1; i++)
                        {
                            DataSet dsmed = mgr.ExecuteQuery("select MedicalSchool from tbl_medicalschool where isdelete=0 and  id=" + strMedschids[i].ToString(), "tbl");
                            if (dsmed.Tables[0].Rows.Count > 0)
                            {
                                lblMedicalSchool.Text += dsmed.Tables[0].Rows[0]["MedicalSchool"].ToString() + "<br>";
                            }
                        }
                    }
                }
                else
                {
                    lblMedicalSchool.Text = "None";
                }*/
                #endregion

                string[] strHosids = ds_drdet.Tables[0].Rows[0]["HospitalName"].ToString().Split(new char[] { ',' });
                if (ds_drdet.Tables[0].Rows[0]["HospitalName"].ToString() != "")
                {
                    //DataSet dshos = mgr.ExecuteQuery("select HName from tbl_hospitals where id=" + ds_drdet.Tables[0].Rows[0]["HospitalName"].ToString(), "tbl");
                    DataSet dshos = mgr.ExecuteQuery("select HName from tbl_hospitals where id in (select hospital_id from tbl_Dentist_hospital where dnt_id="
                        + id.ToString() + ");", "Hospitals");
                    if (dshos.Tables[0].Rows.Count > 0)
                    {
                        //lblHospital.Text = dshos.Tables[0].Rows[0]["HName"].ToString();

                        //changed as per client's request : K
                        //December 2, 2006
                        lblHospital.Text = "";
                        for (int i = 0; i <= dshos.Tables[0].Rows.Count - 1; i++)
                        {
                            lblHospital.Text += dshos.Tables[0].Rows[i]["HName"].ToString() + "<br>";
                        }
                        lblHospital.Text = lblHospital.Text.Substring(0, lblHospital.Text.Length - 4);
                    }
                    else
                    {
                        lblHospital.Text = "None";
                    }
                }
                else
                {
                    lblHospital.Text = "Not Available";
                }
                
                string[] strInsuranceId = ds_drdet.Tables[0].Rows[0]["InsuranceIds"].ToString().Split(new char[] { ',' });

                SqlDataReader rdr = mgr.ExecuteQuery("select i.Name from tbl_dentist_insurance di left join tbl_insurancecompanies i on i.id = di.insuranceid where di.dentistid=" + id.ToString());

                while (rdr.Read())
                {
                    lblInsurance.Text += rdr["name"].ToString() + "; ";
                }
                rdr.Close();

                //if (ds_drdet.Tables[0].Rows[0]["InsuranceIds"].ToString() != "")
                //{
                //    if (strInsuranceId.Length != 0)
                //    {
                //        for (int i = 0; i < strInsuranceId.Length - 1; i++)
                //        {
                //            DataSet dsInsurance = mgr.ExecuteQuery("select name from tbl_InsuranceCompanies where id=" + strInsuranceId[i].ToString(), "tblInsurance");
                //            if (dsInsurance.Tables[0].Rows.Count > 0)
                //            {
                //                lblInsurance.Text += dsInsurance.Tables[0].Rows[0]["name"].ToString() + ",";
                //            }
                //        }
                //    }
                //}

                lblInsurance.Text = lblInsurance.Text.Length > 0 ? lblInsurance.Text : "Not Available";
                lblSpeciality.Text = Convert.ToBoolean(String.Compare(ds_drdet.Tables[0].Rows[0]["SpecialityID"].ToString(), "0")) ? ds_drdet.Tables[0].Rows[0]["SpecialityID"].ToString() : "";
                lblSSpecialty.Text = Convert.ToBoolean(String.Compare(ds_drdet.Tables[0].Rows[0]["SecondarySpecialityID"].ToString(), "0")) ? ", " + ds_drdet.Tables[0].Rows[0]["SecondarySpecialityID"].ToString() : "";

                if (String.Compare(ds_drdet.Tables[0].Rows[0]["Abms_CertificationID"].ToString(), "False") == 0)
                { lblAbms.Text = "No"; }
                else
                { lblAbms.Text = "Yes"; }

                if (String.Compare(ds_drdet.Tables[0].Rows[0]["AcceptNew"].ToString(), "False") == 0)
                { lbl_new.Text = "No"; }
                else
                { lbl_new.Text = "Yes"; }

                if (ds_drdet.Tables[0].Rows[0]["overallrate"].ToString() != null && ds_drdet.Tables[0].Rows[0]["overallrate"].ToString() != "")
                {
                    overallRate = Convert.ToDouble(ds_drdet.Tables[0].Rows[0]["overallrate"]);
                    if (overallRate > 100) overallRate = 100;

                    ///K: 12 oct 2006
                    ///if the Dentists are rated below 50 they should be labeled as 'Not Rated'

                    //lblOver.Text = Math.Round(overallRate, 2).ToString();

                    float fRateLimit = Convert.ToSingle(ConfigurationManager.AppSettings["MinRatingLimit"].ToString());
                    lblOver.Text = ((overallRate >= fRateLimit) ? Math.Round(overallRate, 2).ToString() : "Not Rated");
                    lblOver.ForeColor = ((overallRate >= fRateLimit) ? System.Drawing.Color.Blue : System.Drawing.Color.Red);
                    ///k: code ends                    

                    // overallRate.rate = Convert.ToDecimal(ds_drdet.Tables[0].Rows[0]["overallrate"].ToString());
                    //overallRate.totalScore = 100;
                }

                // premium features
           //     Response.Write("------" + ds_drdet.Tables[0].Rows[0]["featured"].ToString());
                if (ds_drdet.Tables[0].Rows[0]["featuretype"] != DBNull.Value )
                {
                if (Convert.ToInt32(ds_drdet.Tables[0].Rows[0]["featuretype"]) > 0)
                {
                    string str_path = String.Empty;
                    if (System.IO.File.Exists(Request.PhysicalApplicationPath + "/images/Dnt_images/" + ds_drdet.Tables[0].Rows[0]["photo"].ToString()))
                    {
                        if (ds_drdet.Tables[0].Rows[0]["photo"].ToString().Trim().Length > 0)
                        {
                           
                            str_path = getThumbnaleImageWithURLFormat(ds_drdet.Tables[0].Rows[0]["photo"].ToString(), 130, 100, false, "", Session["strhttp"].ToString());
                        }
                        else
                        {
                            str_path = getThumbnaleImageWithURLFormat(ds_drdet.Tables[0].Rows[0]["photo"].ToString(), 130, 100, false, "", Session["strhttp"].ToString());
                            
                        }
                    }
                    else
                    {
                        str_path = getThumbnaleImageWithURLFormat(ds_drdet.Tables[0].Rows[0]["photo"].ToString(), 130, 100, false, "", Session["strhttp"].ToString());
                       
                    }

                    gender.Text = ds_drdet.Tables[0].Rows[0]["gender"].ToString();
                    imgTag.Text = str_path;
                    if (ds_drdet.Tables[0].Rows[0]["profile_desc"].ToString().Length > 0)
                    {
                        lbl_about.Text = "<b>About this Dentist</b>  : " + ds_drdet.Tables[0].Rows[0]["profile_desc"].ToString();
                    }
                    lbl_web.Text = "<a href='" + ds_drdet.Tables[0].Rows[0]["web"].ToString() + "' target='_blank'>" + ds_drdet.Tables[0].Rows[0]["web"].ToString() + "</a>";
                }}
                /*else
                {
                    img_dr.Visible = false;
                }*/


                //Dentist Endorsement
                lbl_endorse.Text = ds_drdet.Tables[0].Rows[0]["countpeerref"].ToString();


                #region -- Show Checks --

                //Overall Rating

                SqlParameter[] sqlParamRate = new SqlParameter[1];
                sqlParamRate[0] = new SqlParameter("@dnt_id", SqlDbType.Int);
                sqlParamRate[0].Value = id;
                DataSet dsRating = mgr.ExecuteQuery("get_ratingbydntid", sqlParamRate, "tbl");

                decimal strMedicalSchoolRate = 0.0M;                
                
                if (dsRating.Tables[0].Rows.Count > 0)
                {

                    if (dsRating.Tables[0].Rows[0]["medical"].ToString() != "")
                    {
                        MedicalSchoolRate.rate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["medical"].ToString());
                        MedicalSchoolRate.totalScore = 10;
                        strMedicalSchoolRate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["medical"].ToString());
                    }
                    else
                    {
                        strMedicalSchoolRate = 0.0M;
                    }
                    //Dentist Endorsement for doctor/dentist    - 30, Jul 2007
                    //begin
                    if (dsRating.Tables[0].Rows[0]["medical"].ToString() != "")
                    {
                        MedicalSchoolRate.rate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["medical"].ToString());
                        MedicalSchoolRate.totalScore = 10;
                        strMedicalSchoolRate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["medical"].ToString());
                    }
                    else
                    {
                        strMedicalSchoolRate = 0.0M;
                    }
                    //end
                    decimal strcertRate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["cert"].ToString());

                    TrainingRate.rate = strMedicalSchoolRate + strcertRate;
                    TrainingRate.totalScore = 10;
                    
                    decimal strDentistEndorsementRate = 0.0M;
                    decimal strYearsExpRate = 0.0M;                    

                    if (dsRating.Tables[0].Rows[0]["Endorsement"].ToString() != "")
                    {
                        Endorsements.rate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["Endorsement"].ToString());
                        Endorsements.totalScore = 15;
                        strDentistEndorsementRate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["Endorsement"].ToString());
                    }
                    else
                    {
                        strDentistEndorsementRate = 0.0M;
                    }

                    if (dsRating.Tables[0].Rows[0]["experience"].ToString() != "")
                    {
                        YearsExpRate.rate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["experience"].ToString());
                        YearsExpRate.totalScore = 20;
                        strYearsExpRate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["experience"].ToString());
                    }
                    else
                    {
                        strYearsExpRate = 0.0M;
                    }

                    // overall expertise
                    ExpertiseRate.rate = strDentistEndorsementRate + strYearsExpRate;
                    ExpertiseRate.totalScore = 35;

                    // patient review
                    decimal strOfficeStaffRate = 0.0M;
                    decimal strOfficeSettingRate = 0.0M;
                    decimal strWaitRate = 0.0M;
                    decimal strClinicalKnowledgeRate = 0.0M;
                    decimal strPatientTreatmentRate = 0.0M;
                    decimal strPatientConfidenceRate = 0.0M;
                    decimal strPatientSatisfactionRate = 0.0M;


                    //OfficeSettingRate

                    if (dsRating.Tables[0].Rows[0]["Off_Staff"].ToString() != "")
                    {
                        OfficeStaffRate.rate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["Off_Staff"].ToString());
                        OfficeStaffRate.totalScore = 5.0M;
                        strOfficeStaffRate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["Off_Staff"].ToString());
                    }
                    else
                    {
                        strOfficeStaffRate = 0.0M;
                    }

                    if (dsRating.Tables[0].Rows[0]["Off_Setting"].ToString() != "")
                    {
                        OfficeSettingRate.rate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["Off_Setting"].ToString());
                        OfficeSettingRate.totalScore = 5.0M;
                        strOfficeSettingRate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["Off_Setting"].ToString());
                    }
                    else
                    {
                        strOfficeStaffRate = 0.0M;
                    }


                    if (dsRating.Tables[0].Rows[0]["Wait_Time"].ToString() != "")
                    {
                        WaitRate.rate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["Wait_Time"].ToString());
                        WaitRate.totalScore = 5.0M;
                        strWaitRate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["Wait_Time"].ToString());
                    }
                    else
                    {
                        strWaitRate = 0.0M;
                    }

                    if (dsRating.Tables[0].Rows[0]["Dnt_Knw"].ToString() != "")
                    {
                        ClinicalKnowledgeRate.rate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["Dnt_Knw"].ToString());
                        ClinicalKnowledgeRate.totalScore = 5.0M;
                        strClinicalKnowledgeRate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["Dnt_Knw"].ToString());
                    }
                    else
                    {
                        strClinicalKnowledgeRate = 0.0M;
                    }

                    if (dsRating.Tables[0].Rows[0]["Pat_Trt"].ToString() != "")
                    {
                        PatientTreatmentRate.rate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["Pat_Trt"].ToString());
                        PatientTreatmentRate.totalScore = 5.0M;
                        strPatientTreatmentRate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["Pat_Trt"].ToString());
                    }
                    else
                    {
                        strPatientTreatmentRate = 0.0M;
                    }

                    if (dsRating.Tables[0].Rows[0]["Pat_Confidence"].ToString() != "")
                    {
                        PatientConfidenceRate.rate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["Pat_Confidence"].ToString());
                        PatientConfidenceRate.totalScore = 5.0M;
                        strPatientConfidenceRate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["Pat_Confidence"].ToString());
                    }
                    else
                    {
                        strPatientConfidenceRate = 0.0M;
                    }
                    if (dsRating.Tables[0].Rows[0]["Pat_Satisfy"].ToString() != "")
                    {
                        PatientSatisfactionRate.rate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["Pat_Satisfy"].ToString());
                        PatientSatisfactionRate.totalScore = 10.0M;
                        strPatientSatisfactionRate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["Pat_Satisfy"].ToString());
                    }
                    else
                    {
                        strPatientSatisfactionRate = 0.0M;
                    }
                    PatientOpinionRate.rate = strOfficeStaffRate + strOfficeSettingRate + strWaitRate + strClinicalKnowledgeRate + strPatientTreatmentRate + strPatientConfidenceRate + strPatientSatisfactionRate;
                    PatientOpinionRate.totalScore = 40;

                    // cost
                    if (dsRating.Tables[0].Rows[0]["cost"].ToString() != "")
                    {
                        costRate.rate = Convert.ToDecimal(dsRating.Tables[0].Rows[0]["cost"].ToString());
                    }
                }
                #endregion
            }
            else
            {
                MultiView1.SetActiveView(View2);
                lblMsg.Text = "No Records found";
                lblMsg.ForeColor = System.Drawing.Color.Red;
                lblMsg.Font.Bold = true;
            }
                

                


                //***************************************************************************************************
                //***************************************************************************************************
            
        }
        // catch (Exception ex)
        {
            //   Response.Write(ex.Message);
        }
    }
    #endregion

    protected void btnBack_Click(object sender, EventArgs e)
    {
        //Redirect the page
        string goToCode = "";
        if (ViewState["pageFromOrAction"] != null)
            Session["pageFromOrAction"] = ViewState["pageFromOrAction"];
        if (Session["pageFromOrAction"] != null || Session["pageFromOrAction"].ToString() != "")
        {
            goToCode = Session["pageFromOrAction"].ToString();
            if (goToCode == "CommunityPage")
            {

                Response.Redirect(Session["strHttps"] + "SearchResultDenCom.aspx");

            }
            else
            {
                Response.Redirect(Session["strHttps"] + "SearchResultsDent.aspx");
            } 
            
        }
        else
        {
            Response.Redirect(Session["strHttp"] + "SearchResults_dentist.aspx");
        }

    }
    protected void linkViewPostMessage_Click(object sender, EventArgs e)
    {
        //Redirect the page
        string Identity = "";
        Encryption objEncription = new Encryption();

        //Added at 190908

        //Identity = Request.QueryString["Id"].ToString();
        Session["isToDoctorOrDentist"] = "Dentist"; 
        if (Request.QueryString["Id"] != null)
        {
            Identity = Request.QueryString["Id"].ToString();
        }
        else if (RewriteModule.RewriteContext.Current.Params["Id"] != null)
        {
            Identity = RewriteModule.RewriteContext.Current.Params["Id"].ToString();
        }         

        //End


        Identity += ",2";
        Identity = objEncription.QueryStringEncode(Identity);
        if (Session["pageFromOrAction"] != null || Session["pageFromOrAction"].ToString() == "")
        {
           // Response.Redirect(Session["strHttp"] + "dentist/dentistViewMessage.aspx?id=" + Identity);
            Response.Redirect(Session["strHttp"].ToString() + "Community/FacePage.aspx");//Added By Wahaj Khan Nov 30 2011
        }
    }


       protected void lnlAddtoMyDentist_Click(object sender, EventArgs e)
    {
        //Added at 190908

        //Response.Redirect(Session["strHttp"] + "User/MyDentists.aspx?id=" + Request.QueryString["Id"]);
        if (Request.QueryString["Id"] != null)
        {
            Response.Redirect(Session["strHttp"] + "User/MyDentists.aspx?id=" + Request.QueryString["Id"]);
        }
        else if (RewriteModule.RewriteContext.Current.Params["Id"] != null)
        {
            Response.Redirect(Session["strHttp"] + "User/MyDentists.aspx?id=" + RewriteModule.RewriteContext.Current.Params["Id"]);
        } 

        //End
    }

    public void IncreaseViewCounter()
    {
        try
        {
            Manager objManager = new Manager(true,"ConnectionString");
            if (Session["userID"] != null && !Session["userID"].ToString().Length.Equals(0))
            {
                if (Convert.ToInt32(Session["userID"]) == Convert.ToInt32(Request.QueryString["Id"]))
                {
                    return;
                }
                else if (Convert.ToInt32(Session["userID"]) == Convert.ToInt32(RewriteModule.RewriteContext.Current.Params["Id"]))
                {
                    return;
                }
            }
            else
            {

                SqlParameter[] objSqlParameter = new SqlParameter[2];
                objSqlParameter[0] = new SqlParameter("@DentistID", SqlDbType.BigInt);

                //objSqlParameter[0].Value = Convert.ToInt32(Request.QueryString["Id"]);

                if (Request.QueryString["Id"] != null)
                {
                    objSqlParameter[0].Value = Convert.ToInt32(Request.QueryString["Id"]);
                }
                else if (RewriteModule.RewriteContext.Current.Params["Id"] != null)
                {
                    objSqlParameter[0].Value = Convert.ToInt32(RewriteModule.RewriteContext.Current.Params["Id"]);
                }
                objSqlParameter[1] = new SqlParameter("@DentistType", SqlDbType.BigInt);
                objSqlParameter[1].Value = 4;
                objManager.ExecuteQuery("AddAndUpdateDentistProfileView", objSqlParameter);
                objManager = null;
            }
        }
            
        catch(Exception ex)
        {
            Response.Write(ex.Message.ToString());
           //Response.End();

        }

    }


    public string getThumbnaleImageWithURLFormat(string imgName, int maxWidth, int maxHeight, bool saveImage, string savePath, string baseURL)
    {
        string s;
        double imgHeight, imgWidth;
        //Response.Write(imgName) ;
        s = Server.MapPath("~/images/dnt_images/" + imgName);
        //Response.Write("<br>"+s);
        System.Drawing.Image currentImage = System.Drawing.Image.FromFile(s);
        imgHeight = currentImage.Height;
        imgWidth = currentImage.Width;
        if (imgWidth > maxWidth | imgHeight > maxHeight)
        {
            double deltaWidth = imgWidth - maxWidth;
            double deltaHeight = imgHeight - maxHeight;
            double scaleFactor;
            if (deltaHeight > deltaWidth)
                scaleFactor = maxHeight / imgHeight;
            else
                scaleFactor = maxWidth / imgWidth;
            imgWidth *= scaleFactor;
            imgHeight *= scaleFactor;
        }

        if (saveImage)
        {
            if (savePath == "")
                throw new Exception("must pass a file name");
            currentImage.GetThumbnailImage(Convert.ToInt32(imgWidth), Convert.ToInt32(imgHeight), null, IntPtr.Zero).Save(Server.MapPath(savePath));
            currentImage.Dispose();
        }
        //return currentImage.GetThumbnailImage(Convert.ToInt32(imgWidth), Convert.ToInt32(imgHeight), null, IntPtr.Zero);


        return ("<img src=\"" + baseURL + "images/dnt_images/" + imgName + "\"" + " height=\"" + imgHeight + "\" width=\"" + imgWidth + "\" border='0' alt=''/>");
    }

    public void GetSelectedDoctorName(int id)
    {
        string strSql = "select id,fname,lname from tbl_dentists where Id='" + id + "'";
        SqlDataReader sqlDr = mgr.ExecuteQuery(strSql);
        if (sqlDr.Read())
        {

            Session["DoctorNameeee"] = sqlDr["fname"].ToString() + " " + sqlDr["lname"].ToString();
            string DocName = Session["DoctorNameeee"].ToString();
            // HttpContext.Current.Session["DoctorType"] = "Dentist";
            sqlDr.Close();

        }
    }
}
